{
 "cells": [
  {
   "cell_type": "code",
   "metadata": {
    "collapsed": true,
    "pycharm": {
     "name": "#%% \n"
    }
   },
   "source": [
    "# -*- coding: utf-8 -*-\n",
    "# @Author   : liyi\n",
    "# @Time     : 2023/4/7 22:42\n",
    "# @File     : new_analysis.py\n",
    "# @Project  : ai_quant_trade\n",
    "# Copyright (c) Personal 2022 liyi\n",
    "# Function Description: \n",
    "#\n",
    "# Licensed under the Apache License, Version 2.0 (the \"License\");\n",
    "# you may not use this file except in compliance with the License.\n",
    "# You may obtain a copy of the License at\n",
    "#\n",
    "#     http://www.apache.org/licenses/LICENSE-2.0\n",
    "#\n",
    "# Unless required by applicable law or agreed to in writing, software\n",
    "# distributed under the License is distributed on an \"AS IS\" BASIS,\n",
    "# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n",
    "# See the License for the specific language governing permissions and\n",
    "# limitations under the License."
   ],
   "execution_count": null,
   "outputs": []
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "outputs": [],
   "source": [
    "from modelscope.pipelines import pipeline\n",
    "from modelscope.utils.constant import Tasks\n",
    "\n",
    "import qstock as qs"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n",
     "is_executing": false
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "outputs": [
    {
     "name": "stderr",
     "text": [
      "100%|██████████| 1/1 [00:00<00:00,  5.33it/s]\n"
     ],
     "output_type": "stream"
    },
    {
     "data": {
      "text/plain": "              datetime                                            content\n0  2023-04-08 04:00:32         截止至4月4日当周CFTC商品类非商业持仓报告在金十数据中心更新啦！欢迎点击查看>>\n1  2023-04-08 04:00:34          截止至4月4日当周CFTC商品类商业持仓报告在金十数据中心更新啦！欢迎点击查看>>\n2  2023-04-08 04:00:37         截止至4月4日当周CFTC外汇类非商业持仓报告在金十数据中心更新啦！欢迎点击查看>>\n3  2023-04-08 04:00:40          截止至4月4日当周CFTC外汇类商业持仓报告在金十数据中心更新啦！欢迎点击查看>>\n4  2023-04-08 04:00:48  【一季度逾70家拟IPO企业“弃考”，因板块定位不符或自身实力不济】金十数据4月8日讯，一季...",
      "text/html": "<div>\n<style scoped>\n    .dataframe tbody tr th:only-of-type {\n        vertical-align: middle;\n    }\n\n    .dataframe tbody tr th {\n        vertical-align: top;\n    }\n\n    .dataframe thead th {\n        text-align: right;\n    }\n</style>\n<table border=\"1\" class=\"dataframe\">\n  <thead>\n    <tr style=\"text-align: right;\">\n      <th></th>\n      <th>datetime</th>\n      <th>content</th>\n    </tr>\n  </thead>\n  <tbody>\n    <tr>\n      <th>0</th>\n      <td>2023-04-08 04:00:32</td>\n      <td>截止至4月4日当周CFTC商品类非商业持仓报告在金十数据中心更新啦！欢迎点击查看&gt;&gt;</td>\n    </tr>\n    <tr>\n      <th>1</th>\n      <td>2023-04-08 04:00:34</td>\n      <td>截止至4月4日当周CFTC商品类商业持仓报告在金十数据中心更新啦！欢迎点击查看&gt;&gt;</td>\n    </tr>\n    <tr>\n      <th>2</th>\n      <td>2023-04-08 04:00:37</td>\n      <td>截止至4月4日当周CFTC外汇类非商业持仓报告在金十数据中心更新啦！欢迎点击查看&gt;&gt;</td>\n    </tr>\n    <tr>\n      <th>3</th>\n      <td>2023-04-08 04:00:40</td>\n      <td>截止至4月4日当周CFTC外汇类商业持仓报告在金十数据中心更新啦！欢迎点击查看&gt;&gt;</td>\n    </tr>\n    <tr>\n      <th>4</th>\n      <td>2023-04-08 04:00:48</td>\n      <td>【一季度逾70家拟IPO企业“弃考”，因板块定位不符或自身实力不济】金十数据4月8日讯，一季...</td>\n    </tr>\n  </tbody>\n</table>\n</div>"
     },
     "metadata": {},
     "output_type": "execute_result",
     "execution_count": 4
    }
   ],
   "source": [
    "# df_news = qs.news_data()  # 获取财联社新闻\n",
    "df_js = qs.news_data('js')  # 获取市场快讯\n",
    "df_js.head()\n"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n",
     "is_executing": false
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "outputs": [
    {
     "name": "stdout",
     "text": [
      "{'scores': [0.8106534481048584, 0.18934649229049683], 'labels': ['正面', '负面']}\n"
     ],
     "output_type": "stream"
    }
   ],
   "source": [
    "semantic_cls = pipeline(Tasks.text_classification, 'damo/nlp_structbert_sentiment-classification_chinese-base')\n",
    "res = semantic_cls(input=df_js['content'][0])  # 对第一条新闻进行情绪分析\n",
    "\n",
    "# scores 分别是负面和正面的概率分数\n",
    "print(res)\n"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n",
     "is_executing": false
    }
   }
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.6"
  },
  "pycharm": {
   "stem_cell": {
    "cell_type": "raw",
    "source": [],
    "metadata": {
     "collapsed": false
    }
   }
  }
 },
 "nbformat": 4,
 "nbformat_minor": 0
}